import router from '.';
import NProgress from "../../config/nprogress";
import { getToken } from "@/utils/auth";

const whiteList = ['/login']

router.beforeEach(async (to: any, _, next) => {
  NProgress.start();
  const hasToken = getToken();

  if (hasToken) {
    // 已登录 已登录时访问login直接进入login
    if (to.path === '/login') {
      NProgress.done();
      next()
    } else {
      next();
    }
  } else {
    // 未登录
    if (whiteList.indexOf(to.path) !== -1) {
      next();
    } else {
      next('/login');
      NProgress.done();
    }
  }
});

router.afterEach(() => {
  NProgress.done();
});



